﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Cstudy.DAL
{
    public class Topics
    {
        public bool AddTopic(MODEL.Topics topics)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@title",topics.Title),
                new SqlParameter("@content",topics.Content),
                new SqlParameter("@authorid",topics.Authorid),
                new SqlParameter("@states",(int)topics.States)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_AddTopic", parms);
        }

        public bool DeleteTopic(int topicid)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@topicid",topicid)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_DeleteTopic", parms);
        }

        public bool UpdateTopic(MODEL.Topics topic)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@Topicid",topic.TopicID),
                new SqlParameter("@title",topic.Title),
                new SqlParameter("@content",topic.Content),
                new SqlParameter("@states",(int)topic.States)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_UpdateTopic", parms);
        }

        public DataSet SelectNewTopic(int count)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@top",count)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SelectNewTopic", parms);
        }

        public DataSet SelectHotTopic(int count)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@top",count)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SelectHotTopic", parms);
        }

        public DataSet SearchTopicByTitle(string keyword)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@keyword",keyword)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SearchTopicByTitle", parms);
        }

        public DataSet SearchTopicByContent(string keyword)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@keyword",keyword)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SearchTopicByContent", parms);
        }


    }
}
